package cn.cloudpower.huabao.activity;

import java.util.ArrayList;
import java.util.List;

import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.Window;
import android.widget.Button;
import android.widget.TabWidget;
import android.widget.TextView;

import com.api.R;
import com.api.TabHostActivity;
import com.api.example.app.TabItem;
 
public class MenuActivity extends TabHostActivity {

	List<TabItem> mItems;
	private LayoutInflater mLayoutInflater; 
	TextView tx = null;
	public static Handler handlertemp;
	
	private Handler handler = new Handler(){
		@Override
		public void handleMessage(Message msg) {
			// TODO Auto-generated method stub
			super.handleMessage(msg);
			switch (msg.what) {
			case 1:
				tx.setText(msg.obj.toString());
				break;
			default:
				break;
			}
		}
		
		
	};
	@Override
	protected void prepare() {
		TabItem home = new TabItem(
				"首页",									// title
				R.drawable.shouye,					// icon
				R.drawable.example_tab_item_bg,			// background
				new Intent(this, BookShelfActivity.class));	// intent
		
		TabItem info = new TabItem(
				"搜索",
				R.drawable.sousuo,
				R.drawable.example_tab_item_bg,
				new Intent(this,SousuoActivity.class));
		
		TabItem msg = new TabItem(
				"下载",
				R.drawable.xiazai,
				R.drawable.example_tab_item_bg,
				new Intent(this, XiazaiActivity.class));
		
		TabItem square = new TabItem(
				"个人",
				R.drawable.yonghu,
				R.drawable.example_tab_item_bg,
				new Intent(this, YonghuguanliActivity.class));
		
//		TabItem more = new TabItem(
//				"更多",
//				R.drawable.icon_more,
//				R.drawable.example_tab_item_bg,
//				new Intent(this, Tab5Activity.class));
		
		mItems = new ArrayList<TabItem>();
		mItems.add(home);
		mItems.add(info);
		mItems.add(msg);
		mItems.add(square);
//		mItems.add(more);

		 	
		TabWidget tabWidget = getTabWidget();
		tabWidget.setDividerDrawable(R.drawable.tab_divider);
		
		mLayoutInflater = getLayoutInflater();
	}
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		Button myShelf = (Button) findViewById(R.id.myshelf);
		myShelf.setOnClickListener(new OnClickListener() {
			
			public void onClick(View v) {
				Intent intent = new Intent(MenuActivity.this, MyShelfActivity.class);
				startActivity(intent);
			}
		});
		handlertemp = handler;
		tx = (TextView)findViewById(R.id.head_title);
		setCurrentTab(0);
	}
	
	 
	@Override
	protected void setTabItemTextView(TextView textView, int position) {
		textView.setPadding(3, 3, 3, 3);
		textView.setText(mItems.get(position).getTitle());
		textView.setBackgroundResource(mItems.get(position).getBg());
		textView.setCompoundDrawablesWithIntrinsicBounds(0, mItems.get(position).getIcon(), 0, 0);
		
	}
 
	@Override
	protected String getTabItemId(int position) {
		return mItems.get(position).getTitle();
 
		}
 
	@Override
	protected Intent getTabItemIntent(int position) {
		return mItems.get(position).getIntent();
	}

	@Override
	protected int getTabItemCount() {
		return mItems.size();
	}  
 
	@Override
	protected View getTop() {
		return mLayoutInflater.inflate(R.layout.head, null);
	}
}
